package cn.xspace.app.filemg.view;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.TextView;

import com.xspace.android.xafcommon.util.BaseRProxy;

import java.util.ArrayList;

import cn.xspace.app.filemg.bean.FileInfo;
import cn.xspace.app.filemg.util.FileMg;

public class VideoGridAdapter extends ArrayAdapter<FileInfo> {
	private Context context;

	public VideoGridAdapter(Context context, ArrayList<FileInfo> objects) {
		super(context, 0, objects);
		this.context = context;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		ViewHolder viewHolder;
		if (convertView == null) {
			LayoutInflater inflater = ((Activity) context).getLayoutInflater();
			convertView = inflater.inflate(BaseRProxy.video_grid_item, null);
			viewHolder = new ViewHolder(convertView);
		
			convertView.setTag(viewHolder);
		} else {
			viewHolder = (ViewHolder) convertView.getTag();
		}
		FileInfo info = getItem(position);
		viewHolder.title.setText(info.getName());
		viewHolder.mSize
				.setText(FileMg.FormetFileSize(info.getSize()));
//		if (info.getApkIoc() == null || "".equals(info.getApkIoc())) {
//			info.setApkIoc(FileMg.getVideoThumbnail(info.getPath()));
//			viewHolder.image.setBackgroundDrawable(info.getApkIoc());
//		} else {
			viewHolder.image.setBackgroundDrawable(info.getApkIoc());
			viewHolder.mBox.setChecked(info.isCheckFlag());
		return convertView;
	}

	class ViewHolder {
		public TextView title;
		public TextView mSize;
		public ImageView image;
		public CheckBox mBox;
		public ViewHolder(View v){
			title = (TextView) v
					.findViewById(BaseRProxy.ItemText);
			image = (ImageView) v
					.findViewById(BaseRProxy.ItemImage);
			mSize = (TextView) v
					.findViewById(BaseRProxy.video_size);
			mBox = (CheckBox) v.findViewById(BaseRProxy.box);
		}
	}
}
